#include <gmock/gmock.h>

#include <string>
class Test {
public:
    Test()  = default;
    ~Test() = default;

    // gmock依赖多态实现模拟类行为，被模拟的函数必须声明为virtual才行，不一定纯虚
    virtual int         GetInt()      = 0;
    virtual std::string GetString()   = 0;
    virtual int         GetInt(int)   = 0;
    virtual int         Add(int, int) = 0;
};

class TestMock : public Test {
public:
    TestMock()  = default;
    ~TestMock() = default;
    // METHOD后的数字用来标识函数的入参数量
    MOCK_METHOD0(GetInt, int());
    MOCK_METHOD0(GetString, std::string());
    MOCK_METHOD1(GetInt, int(int));
    MOCK_METHOD2(Add, int(int, int));
};

TEST(TestMock, Function) {
    TestMock t;
    EXPECT_CALL(t, GetInt()).Times(1).WillOnce(testing::Return(1));
    auto a = t.GetInt();
    EXPECT_EQ(a, 1);

    EXPECT_CALL(t, GetString()).Times(1).WillOnce(testing::Return("Mock"));

    auto b = t.GetString();
    EXPECT_EQ(b, "Mock");

    EXPECT_CALL(t, GetInt(testing::_)).Times(1).WillOnce(testing::Return(1));
    auto c = t.GetInt(1);
    EXPECT_EQ(c, 1);

    EXPECT_CALL(t, Add(testing::_, testing::_)).Times(1).WillOnce(testing::Return(5));

    auto d = t.Add(2, 3);
    EXPECT_EQ(d, 5);
}
